package com.xingfly.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.TypeReference;
import com.xingfly.constant.AttributeConstant;
import com.xingfly.model.dto.Seat;
import com.xingfly.model.dto.Temp;
import com.xingfly.model.dto.User;
import com.xingfly.service.ArithmeticService;
import com.xingfly.service.SeatService;
import com.xingfly.service.TempService;
import com.xingfly.service.UserService;
import com.xingfly.suan.flightMan;
/**
 *	临时表控制器
 * @author 心之所向-LQ
 * Created by SuperS on 2019/5/23 0:13
 *
 */
@SuppressWarnings("all")
@Controller
public class TempController {
	@Resource
	private TempService tempService;//临时表业务层
	
	@Resource
	private SeatService seatService;
	
	@Resource
	private UserService userService;
	
	@Resource
	private ArithmeticService arithmeticService;//算法业务层
	private Logger logger=Logger.getLogger(TempController.class);
	/**
	 * 查询临时表全部信息控制器
	 * @return
	 */
	@RequestMapping(value = "getTempAll",produces = "application/json;charset=utf-8")
	@ResponseBody
	public String getTempAll() {
		List<com.xingfly.suan.Temp> selByJoinAll = tempService.SelByJoinAll();
		String result = JSONArray.toJSONString(selByJoinAll);
		System.out.println("临时表联查的信息"+result);
		return result;
	}
	/**
	 * 单人分配算法(为选中的用户分配坐位)
	 * @return
	 */
	@RequestMapping(value = "allocationServlet",produces = "application/json;charset=utf-8")
	@ResponseBody
	public String allocationServlet(@RequestParam("users") String users) {
			String result = arithmeticService.singleDistriBution(users);
			return result;
	}
	/**
	 * 删除临时表信息(清空坐位)
	 */
	@RequestMapping(value = "clearSeatServlet",produces ="text/html;charset=utf-8")
	@ResponseBody
	public String  deleteall() {
		int deleteByAll = tempService.deleteByAll();
		int updateByAllatstate = seatService.UpdateByAllatstate();
		int updUserAll = userService.updUserAll();
		String valueOf = String.valueOf(deleteByAll);
		return valueOf;
	}
	/**
	 * 整仓分配算法
	 * @param users
	 * @return
	 */
	@RequestMapping(value = "warehouse",produces ="application/json;charset=utf-8")
	@ResponseBody
	public String warehouse() {
		String result=arithmeticService.warehouse();
		return result;
	}
	
}
